<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html xmlns:th="http://www.thymeleaf.org">

<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" name="viewport">
<meta content="yes" name="apple-mobile-web-app-capable">
<meta content="black" name="apple-mobile-web-app-status-bar-style">
<meta content="telephone=no" name="format-detection">
<link rel="stylesheet" href="../static/bootstrap/css/bootstrap.min.css" />
<link rel="stylesheet" type="text/css" href="../static/easyui/themes/bootstrap/easyui.css">
<link rel="stylesheet" type="text/css" href="../static/easyui/themes/icon.css">
<link rel="stylesheet" href="../static/metisMenu/metisMenu_custom.css" />
<link rel="stylesheet" href="../static/css/style-app.css" />
<script src="../static/jquery/jquery-1.12.4.js"></script>
<script src="../static/easyui/jquery.easyui.min.js"></script>
<script src="../static/easyui/locale/easyui-lang-zh_CN.js"></script>
<script src="../static/jqueryValidate/jquery.validate.min.js"></script>
<script src="../static/jqueryValidate/additional-methods.min.js"></script>
<script src="../static/jqueryValidate/localization/messages_zh.min.js"></script>
<script src="../static/moment/moment.js"></script>
<script src="../static/moment/locale/zh-cn.js"></script>
<title>物资审核</title>
</head>

<body>
	<div class="top-part">
		<div class="header">
			<div class="return">
				<a href="javascript:history.go(-1);"></a>
			</div>
			<div class="header-title">物资审核管理</div>
		</div>

	</div>
	<div class="new-form">
		<div>
			<form id="ff" method="post">
				<table cellpadding="5" style="margin: auto;">
					<tr>
						<td style="width: 100px;">项目</td>
						<td>
							<input class="easyui-combobox" data-options="readonly:true" id="projectitem" name="projectitem"
								style="width: 100%;" />
						</td>
					</tr>
					<tr>
						<td style="width: 100px;">名称：</td>
						<td>
							<input class="easyui-textbox" data-options="readonly:true" id="name" name="name" style="width: 100%;" />
						</td>
					</tr>
					<tr>
						<td style="width: 100px;">规格：</td>
						<td>
							<input class="easyui-textbox" data-options="readonly:true" id="specs" name="specs" style="width: 100%;" />
						</td>
					</tr>
					<tr>
						<td style="width: 100px;">单位：</td>
						<td>
							<input class="easyui-textbox" data-options="readonly:true" id="unit" name="unit" style="width: 100%;" />
						</td>
					</tr>
					<tr>
						<td style="width: 100px;">初数：</td>
						<td>
							<input class="easyui-textbox" data-options="readonly:true" id="initial" name="initial"
								style="width: 100%;" />
						</td>
					</tr>
					<tr>
						<td style="width: 100px;">备注：</td>
						<td colspan="4">
							<input class="easyui-textbox" id="remark" name="remark" data-options="readonly:true,multiline:true"
								style="width: 100%; height: 80px;" />
						</td>
					</tr>
					<tr>
						<td style="width: 100px;">拒绝理由：</td>
						<td>
							<input class="easyui-textbox" id="reason" name="reason" style="width: 100%; height: 80px;"
								data-options="multiline:true" />
						</td>
					</tr>
					<tr>
					<td>附件：</td>
						<td id="td1"></td>
					</tr>
				</table>
			</form>
			<div style="text-align: center;" class="search-input">
				<a href="#" class="d-btn btn-blue" onclick="savePro()">同意</a>
				<a href="#" class="d-btn btn-red" onclick="disablecommit()">拒绝</a>
			</div>
		</div>
	</div>
</body>
<script th:inline="javascript">
	var currentPro = [[${goods}]];

	$(document).ready(function() {
		$("#projectitem").textbox("setValue", currentPro.item.name);
		$("#name").textbox("setValue", currentPro.name);
		$("#specs").textbox("setValue", currentPro.specs);
		$("#unit").textbox("setValue", currentPro.unit);
		$("#initial").textbox("setValue", currentPro.initial);
		$("#remark").textbox("setValue", currentPro.remark);
		var html='';
		html+='<div class="clear att-imgs">'
		$.each(currentPro.attachments,function(i,val){
			if(isImage(val.url)){
				html+= '<div class="fl"><img onclick="window.open(\'../'+val.url+ 
				'\',\'_blank\', \' toolbar=no, menubar=no, scrollbars=no, resizable=no, location=no, status=no\');" '+
				'src="../'+val.url+'" style="width:100px;"><span>'+val.name+'</span></div>';
			}
			
		});
		html+='</div>'
			$.each(currentPro.attachments,function(i,val){
				if(isImage(val.url)){
					
				}else{
					html+= '<div class="ell"><a href="javascript:void(0)" onclick="attachmentFile('+val.id+',\''+val.name+
					'\')"><span>'+val.name+'</span></a></div>';
				}
				
			});
		$("#td1").append(html);
	});
	
	function isImage(url) {
		var index= url.lastIndexOf(".");
		var ext = url.substr(index+1);
		return [ 'png', 'jpg', 'jpeg', 'bmp', 'gif', 'webp', 'psd', 'svg', 'tiff' ,'ico'].
				indexOf(ext.toLowerCase()) !== -1;
	}
	
	function savePro() {
		$.ajax({
			type : 'POST',
			url : "../reviewgoods.do?flg=true&id="+currentPro.id,
			contentType : "application/json",
			success : function(data) {
				if (data.success) {
					$.messager.alert('审核物资', '审核物资成功', 'success');
				} else {
					$.messager.alert('审核物资', '审核物资失败', 'error');
				}
				window.setInterval("window.location.href=document.referrer", 2000);
			},
			dataType : "json"
		});
	}
	
	function disablecommit() {
		var reason = $("#reason").textbox("getValue");
		$.ajax({
			type : 'POST',
			url : "../reviewgoods.do?flg=false&id="+currentPro.id+"&reason="+reason,
			contentType : "application/json",
			success : function(data) {
				if (data.success) {
					$.messager.alert('审核物资', '审核物资成功', 'success');
				} else {
					$.messager.alert('拒绝物资', '拒绝物资失败', 'error');
				}
				window.setInterval("window.location.href=document.referrer", 2000);
				
			},
			dataType : "json"
		});
	}
	
	function formatDate(time) {
		var date = new Date(time);
		var year = date.getFullYear(), month = date.getMonth() + 1, //月份是从0开始的
		day = date.getDate(), hour = date.getHours(), min = date.getMinutes(), sec = date
				.getSeconds();
		var newTime = year + '-' + month + '-' + day;
		return newTime;
	}

	function viewAtt1(index){
		var row = $('#reviewed_table').datagrid('getRows')[index];
		var tb="";
		$.each(row.attachments,function(i,val){
			if(val.type=='image'){
				tb+= '<div id="att'+val.id+'" class="col-md-3" ><img onclick="window.open(\'../'+val.url+'\',\'_blank\', \' toolbar=no, menubar=no, scrollbars=no, resizable=no, location=no, status=no\');" style="width:100px;height:100px;" src="../'+val.url+'" alt="查看全图"><br>';
				tb+= '<span>'+val.name+'</span><br>';
				tb+= '<a href="javascript:void(0)" class="easyui-linkbutton l-btn l-btn-small" onclick="attachmentFile('+val.id+',\''+val.name+'\')"><span class="l-btn-text">下载</span></a>';
				tb+= '</div>';
			}else{
				tb+= '<div id="att'+val.id+'" class="col-md-3" ><img onclick="window.open(\'../'+val.url+'\',\'_blank\', \' toolbar=no, menubar=no, scrollbars=no, resizable=no, location=no, status=no\');" style="width:100px;height:100px;" src="static/bootstrap/img/'+val.type+'.png" alt="查看全图"><br>';
				tb+= '<span>'+val.name+'</span><br>';
				tb+= '<a href="javascript:void(0)" class="easyui-linkbutton l-btn l-btn-small" onclick="attachmentFile('+val.id+',\''+val.name+'\')"><span class="l-btn-text">下载</span></a>';
				tb+= '</div>';
			}
		});
		$('#displayAtt').empty().html(tb);
		$('#displayAtt').dialog({
            title: '附件',
            resizable: true,
            closed: false,
            cache: false,
            modal: true
        });
	}
	function viewAtt2(index){
		var row = $('#unreviewed_table').datagrid('getRows')[index];
		var tb="";
		$.each(row.attachments,function(i,val){
			if(val.type=='image'){
				tb+= '<div id="att'+val.id+'" class="col-md-3" ><img onclick="window.open(\'../'+val.url+'\',\'_blank\', \' toolbar=no, menubar=no, scrollbars=no, resizable=no, location=no, status=no\');" style="width:100px;height:100px;" src="../'+val.url+'" alt="查看全图"><br>';
				tb+= '<span>'+val.name+'</span><br>';
				tb+= '<a href="javascript:void(0)" class="easyui-linkbutton l-btn l-btn-small" onclick="attachmentFile('+val.id+',\''+val.name+'\')"><span class="l-btn-text">下载</span></a>';
				tb+= '</div>';
			}else{
				tb+= '<div id="att'+val.id+'" class="col-md-3" ><br>';
				tb+= '<span>'+val.name+'</span><br>';
				tb+= '<a href="javascript:void(0)" class="easyui-linkbutton l-btn l-btn-small" onclick="attachmentFile('+val.id+',\''+val.name+'\')"><span class="l-btn-text">下载</span></a>';
				tb+= '</div>';
			}
		});
		$('#displayAtt').empty().html(tb);
		$('#displayAtt').dialog({
            title: '附件',
            resizable: true,
            closed: false,
            cache: false,
            modal: true
        });
	}

	function attachmentFile(id,name) {
		$.get('../attachmentFile.do?id=' + id, function(data) {
			blob = new Blob([ data ])
			var a = document.createElement('a');
			a.download = name;
			a.href = window.URL.createObjectURL(blob)
			a.click()
		})
	}
</script>

</html>